﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbEnSystemDal
	{
		public DbEnSystemDal()
		{
		}
 		#region Insert
 		public static int Insert(DbEnSystem dbEnSystem)
		{	
			string sql = @"Insert Into DbEnSystem (
					SWebName,
					STitle,
					SKeywords,
					SDescription,
					SIcon,
					SLogo,
					SContactName,
					SWeb400,
					SWebUrl,
					SAddress,
					SEmail,
					SBottom,
					SEditTime,
					SIsUrlReWrite,
					SWebStatus,
					SWebStopAlter,
					SDefaultPayId,
					SDefaultPayName,
					SIfBackMusic,
					SBackMusicPath
				) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',{13},{14},'{15}','{16}','{17}',{18},'{19}')";
			sql = string.Format(sql,
					SqlHelper.String(dbEnSystem.SWebName),
					dbEnSystem.STitle,
					dbEnSystem.SKeywords,
					dbEnSystem.SDescription,
					SqlHelper.String(dbEnSystem.SIcon),
					SqlHelper.String(dbEnSystem.SLogo),
					SqlHelper.String(dbEnSystem.SContactName),
					SqlHelper.String(dbEnSystem.SWeb400),
					SqlHelper.String(dbEnSystem.SWebUrl),
					SqlHelper.String(dbEnSystem.SAddress),
					SqlHelper.String(dbEnSystem.SEmail),
					dbEnSystem.SBottom,
					dbEnSystem.SEditTime,
					dbEnSystem.SIsUrlReWrite,
					dbEnSystem.SWebStatus,
					dbEnSystem.SWebStopAlter,
					SqlHelper.String(dbEnSystem.SDefaultPayId),
					SqlHelper.String(dbEnSystem.SDefaultPayName),
					dbEnSystem.SIfBackMusic,
					SqlHelper.String(dbEnSystem.SBackMusicPath)
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbEnSystem dbEnSystem)
		{	
			string sql = @"Update DbEnSystem set 

					SWebName= '{0}',
					STitle= '{1}',
					SKeywords= '{2}',
					SDescription= '{3}',
					SIcon= '{4}',
					SLogo= '{5}',
					SContactName= '{6}',
					SWeb400= '{7}',
					SWebUrl= '{8}',
					SAddress= '{9}',
					SEmail= '{10}',
					SBottom= '{11}',
					SEditTime= '{12}',
					SIsUrlReWrite= {13},
					SWebStatus= {14},
					SWebStopAlter= '{15}',
					SDefaultPayId= '{16}',
					SDefaultPayName= '{17}',
					SIfBackMusic= {18},
					SBackMusicPath= '{19}'
				where

					SId= {20}";
			sql = string.Format(sql,
					SqlHelper.String(dbEnSystem.SWebName),
					dbEnSystem.STitle,
					dbEnSystem.SKeywords,
					dbEnSystem.SDescription,
					SqlHelper.String(dbEnSystem.SIcon),
					SqlHelper.String(dbEnSystem.SLogo),
					SqlHelper.String(dbEnSystem.SContactName),
					SqlHelper.String(dbEnSystem.SWeb400),
					SqlHelper.String(dbEnSystem.SWebUrl),
					SqlHelper.String(dbEnSystem.SAddress),
					SqlHelper.String(dbEnSystem.SEmail),
					dbEnSystem.SBottom,
					dbEnSystem.SEditTime,
					dbEnSystem.SIsUrlReWrite,
					dbEnSystem.SWebStatus,
					dbEnSystem.SWebStopAlter,
					SqlHelper.String(dbEnSystem.SDefaultPayId),
					SqlHelper.String(dbEnSystem.SDefaultPayName),
					dbEnSystem.SIfBackMusic,
					SqlHelper.String(dbEnSystem.SBackMusicPath),
					dbEnSystem.SId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 sId)
		{
		
			string sql = @"Delete from DbEnSystem where 
					SId= {0}";
			sql = string.Format(sql,
					sId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbEnSystem a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbEnSystem Select(Int32 sId)
		{
			DbEnSystem dbEnSystem = null;
			string sql = @"select a.* from DbEnSystem a  where
					a.SId= {0}
";
			sql = string.Format(sql,
					sId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbEnSystem = new DbEnSystem(ds.Tables[0].Rows[0]);					
			return dbEnSystem;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbEnSystem a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbEnSystem a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbEnSystem a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
